home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
C_QNA.ARJ
/
REDIREC4.TC
< prev
next >
Wrap
Text File
|
1991-04-01
|
792b
|
30 lines
QUESTION: How do I change stdin or stdout to binary for redirection?
ANSWER: The following code demonstrates a technique for accomplishing
this task:
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <sys\stat.h>
/*
** It turns out there are 3 things that need to be done.
** Give the following a try:
*/
void main(void)
{
int hndl = fileno( stdout );
int info = ioctl( hndl, 0 );
setmode( hndl, O_BINARY ); /* handle to binary mode */
ioctl( hndl, 1, (info & 0xff) | 0x20 ); /* device to raw mode */
stdout->flags |= _F_BIN; /* stream to binary mode */
fputc('\n', stdout);
/* do what you need to do here */
ioctl( hndl, 1, info & 0xff ); /* put it back the way it was */
}